<template>
  <div class="card">
    <div class="box" v-for="( item ,index ) in cardData" :key="index">
      <div v-if="!item.cover_img" class="wrap" @click="toTeacherDetails(item.teacher_id)">
        <img :src="item.teacher_avatar" :alt="item.teacher_id" />
        <p>
          <b>{{ item.teacher_name }}</b>
          <br />
          <i>{{ item.introduction }}</i>
        </p>
      </div>
      <div v-else class="cover" @click="toCoverDetails(item.id)">
        <h1>{{ item.title }}</h1>
        <b>公共点击量:{{ item.sales_num }}</b>
        <p>
          <img :src="item.cover_img" alt />
        </p>
        <span>
          <i>{{ item.id }}人报名</i>
          <em>报名费:{{ item.price }}</em>
        </span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Card",

  props: {
    cardData: {
      type: Array,
    },
  },

  methods: {
    toTeacherDetails(id) {
      this.$router.push({
        path: `/indexTeacherDetails`,
        query: {
          id,
        },
      });
    },

    toCoverDetails(id) {
      this.$router.push({
        path: `/indexCoverDetails`,
        query: {
          id,
        },
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.card {
  width: 100%;

  .box {
    width: 100%;

    .wrap {
      width: 100%;
      padding: 15px 20px;
      background-color: #fff;
      display: flex;
      margin-bottom: 10px;
      border-radius: 6px;

      img {
        width: 50px;
        height: 50px;
        border-radius: 50%;
        vertical-align: middle;
      }

      p {
        flex-basis: 85%;
        line-height: 30px;
        padding: 0 20px;
      }

      i {
        color: #aaaaaa;
      }
    }

    .cover {
      display: flex;
      flex-direction: column;
      background-color: white;
      margin-bottom: 10px;
      padding: 15px 20px;
      border-radius: 6px;

      h1 {
        font-size: 18px;
        font-weight: 700;
        margin-bottom: 5px;
      }

      b {
        font-size: 12px;
        margin-bottom: 5px;
      }

      img {
        width: 45px;
        height: 45px;
        border-radius: 50%;
        margin-bottom: 15px;
      }

      span {
        width: 100%;

        i {
          text-align: left;
          float: left;
          color: #aaaaaa;
        }

        em {
          text-align: right;
          float: right;
          color: orange;
        }
      }
    }
  }
}
</style>